package BundleMessage;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.myapplication.AsynTaskActivity;
import com.example.myapplication.R;
import com.example.myapplication.TabNavActivity;

public class BundleDataActivity1 extends AppCompatActivity {
  String userName;
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.data_bundle_layout_1);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Bundle数据传递1");
    setSupportActionBar(toolbar);
    SetUserName();
    SetNextButtonListener();
  }


  public void BackToLastActivity(View view)
  {
    Intent intent = new Intent(this, AsynTaskActivity.class);
    startActivity(intent);
  }
  public void GoToNextActivity(View view)
  {
    Intent intent = new Intent(this, TabNavActivity.class);
    startActivity(intent);
  }
  private void SetNextButtonListener() {
    Button button = (Button) findViewById(R.id.next_button);
    button.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        LoadNextActivity();
      }
    });
  }
  private void SetUserName() {
    userName = "圈弟";
    String welcomeMessage = getString(R.string.welcome_message, userName);
    TextView textView =(TextView) findViewById(R.id.welcome_text);
    textView.setText(welcomeMessage);

  }
  private void LoadNextActivity() {
    Intent intent = new Intent(this, BundleDataActivity2.class);
    Bundle bundle = new Bundle();
    bundle.putString("name", userName);
    intent.putExtras(bundle);

    startActivity(intent);
  }
}
